<?php

namespace App\Admin\Controllers;

use App\Facades\AdminC;
use App\Http\Controllers\Controller;
use App\Models\TiCash;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;

class TiCashController extends Controller
{
    use ModelForm;

    /**
     * 金币提现
     */
    public function bi()
    {
        return AdminC::content(function(Content $content){
            $content->header('金币提现');
            $content->description('列表');
            $content->body($this->biGrid());

        });
    }

    protected function biGrid()
    {
        return AdminC::grid(TiCash::class, function(Grid $grid){
            $grid->model()->where('type', 0);
            $grid->column('','');
            $grid->id('流水号');
            $grid->column('g_member.name','用户');
            $grid->status('状态')->display(function ($status){
                return $this->status_arr[$status];
            });
            $grid->bei('备注');
            $grid->column('g_member.bi','余额(金币)');
            $grid->created_at('时间');

            $grid->actions(function($actions){
                $actions->disableDelete();
                $actions->disableEdit();
                if($actions->row->status == 0){
                    $actions->append('<a href="/admin/tiCash/bi/'.$actions->row->id.'/edit">不通过</a>&nbsp;&nbsp;');            $actions->append('<a href="/admin/tiCash/bi/'.$actions->row->id.'/edit">通过</a>');
                }
            });

            $grid->disableRowSelector();
            $grid->disableExport();
            $grid->disableCreateButton();
        });

    }

    public function edit($id)
    {
        return AdminC::content(function(Content $content) use($id) {
            $content->header('提现管理');
            $content->description('编辑');
            $content->body($this->form()->edit($id));
        });
    }

    protected function form()
    {
        return AdminC::form(TiCash::class, function(Form $form){
            $form->display('id');
            $form->select('status','状态')->options($form->model()->status_arr);
            $form->text('not_pass_reason','不通过原因');
        });
    }

    /**
     * 零钱提现
     */
    public function cash()
    {
        return AdminC::content(function(Content $content){
            $content->header('金币提现');
            $content->description('列表');
            $content->body($this->cashGrid());

        });
    }

    protected function cashGrid()
    {
        return AdminC::grid(TiCash::class, function(Grid $grid){
            $grid->model()->where('type', 1);
            $grid->column('','');
            $grid->id('流水号');
            $grid->column('g_member.name','用户');
            $grid->status('状态')->display(function ($status){
                return $this->status_arr[$status];
            });
            $grid->bei('备注');
            $grid->column('g_member.account','余额(元)');
            $grid->created_at('时间');

            $grid->actions(function($actions){
                $actions->disableDelete();
                $actions->disableEdit();
                if($actions->row->status == 0){
                    $actions->append('<a href="/admin/tiCash/cash/'.$actions->row->id.'/edit">不通过</a>&nbsp;&nbsp;');            $actions->append('<a href="/admin/tiCash/cash/'.$actions->row->id.'/edit">通过</a>');
                }
            });

            $grid->disableRowSelector();
            $grid->disableExport();
            $grid->disableCreateButton();
        });

    }

}
